package cn.itrip.auth.service;

import com.cloopen.rest.sdk.CCPRestSmsSDK;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * @author 瑾
 */
@Service("smsService")
public class SmsServiceImpl implements  SmsService {




    /**
     *  发送一条短信
     * @param to 发送给谁黑
     * @param templateId  模版id
     * @param datas  发送的内容
     */
    @Override
    public void send(String to, String templateId, String[] datas) throws  Exception {
        //初始化sdk
        CCPRestSmsSDK sdk = new CCPRestSmsSDK();
        sdk.init("app.cloopen.com","8883");
        sdk.setAccount("8aaf0708685978ed0168602b00be03eb","d1a02f050bec4a2fa0f4ef6c3e89b2f8");
        sdk.setAppId("8aaf0708685978ed0168602b012c03f1");

        HashMap result =  sdk.sendTemplateSMS(to,templateId,datas);
        //判断短信是否发送成功
        if(result.get("statusCode").equals("000000")){
            System.out.println("---短信发送成功---");
        }else {
            throw new  Exception(result.get("statusCode").toString()+":"+result.get("statusMsg").toString());
        }

        //激活码存入redis



    }
}
